//
//  DMInAppPurchaseManager.h
//  DualMediationSDK
//
//  Created by little People on 2023/6/15.
//

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "../../AD/Common/DMAdDelegate.h"
#import "../../Core/DMLifecycle/Types/DMLifecycleTypes.h"
NS_ASSUME_NONNULL_BEGIN

static NSString *InAppPurchaseFailRefuse = @"该商品暂时无法购买，请稍后重试";
static NSString *InAppPurchaseFailRequest = @"操作失败，请稍后重试";
static NSString *InAppPurchaseFailBuy = @"购买失败，请稍后重试";
static NSString *InAppPurchaseFailResume = @"恢复失败，您未购买过该商品";



@interface DMInAppPurchaseManager : NSObject

+ (instancetype)shareInAppPurchaseManager;
@property (nonatomic, assign) id<DMAdDelegate> delegate;

//发起内购
- (void)launchInAppPurchase:(NSString *)productId;

//恢复内购
- (void)restoreInAppPurchase:(NSString *)productId;

-(void)removeObserver;

- (void)requestProductLists:(NSArray *)array;

// 新增方法
- (DMProductType)getProductType:(NSString *)productId;
- (BOOL)isProductPurchased:(NSString *)productId;
- (void)savePurchaseRecord:(NSString *)productId;
- (void)clearPurchaseRecord:(NSString *)productId;
- (void)handleDuplicateTransaction:(NSString *)transactionId productId:(NSString *)productId;

// 检查恢复购买状态
- (BOOL)isRestoreInProgress;

// 清除会话中的恢复记录（可选，用于重置状态）
- (void)clearSessionRestoreRecords;

// 清除所有非消耗型商品的本地购买记录（供全量恢复使用）
- (void)clearAllNonConsumablePurchaseRecords;

// 检查非消耗型商品是否已经恢复过（持久化检查）
- (BOOL)isProductRestored:(NSString *)productId;

// 清除特定商品的恢复记录（持久化）
- (void)clearRestoredRecord:(NSString *)productId;

// 清除所有恢复记录（持久化）
- (void)clearAllRestoredRecords;

@end

NS_ASSUME_NONNULL_END
